home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / disk / closeDisk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.0 KB  |  153 lines

  1. /*
  2.  *   $RCSfile: closeDisk.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:38 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "sysdefs.h"
  38. #include "ess.h"
  39. #include "checking.h"
  40. #include "trace.h"
  41. #include "error.h"
  42. #include "list.h"
  43. #include "tid.h"
  44. #include "io.h"
  45. #include "lock.h"
  46. #include "object.h"
  47. #include "msgdefs.h"
  48. #include "disk.h"
  49. #include "thread.h"
  50. #include "semaphore.h"
  51. #include "latch.h"
  52. #include "link.h"
  53. #include "bf.h"
  54. #include "volume.h"
  55. #include "threadstate.h"
  56. #include "disk_funcs.h"
  57. #include "bitvec.h"
  58. #include "msgvector.h"
  59. #include "thread_globals.h"
  60. #include "msg_globals.h"
  61. #include "pool.h"
  62. #include "io_globals.h"
  63. #include "queue_consist.h"
  64.  
  65.  int
  66. closeDisk (
  67.     VOLREC         *volRec
  68. )
  69. {
  70.     LINK        *diskLink = volRec->volLink;
  71.     DISKMSG            *message = Active->diskMessage;
  72.  
  73.     TRPRINT(TR_DISK, TR_LEVEL_1, ("closeDisk volid %d", volRec->volid));
  74.  
  75.     /*
  76.      *  Make sure the list structures in the link are ok
  77.      */
  78. #ifdef DEBUG
  79.     if (diskLink != NULL) {
  80.         CHECK_LIST_MAGIC(&(diskLink->list));
  81.         CHECK_LIST_MAGIC(&(diskLink->tcbList));
  82.         CHECK_LIST_MAGIC(&(diskLink->volList));
  83.         CHECK_LIST_MAGIC(&(diskLink->transList));
  84.         CHECK_LIST_MAGIC(&(diskLink->resourceList));
  85.         TRPRINT(TR_DISK, TR_LEVEL_1, ("closeDisk fd %d", diskLink->id));
  86.     }
  87. #endif DEBUG
  88.  
  89.     /*
  90.      *    setup the thread id in the message
  91.      */
  92.     message->header.type = CLOSE_DISK;
  93.  
  94.     /*
  95.      *    send the message
  96.      */
  97.     if (callDisk( volRec, message))    {
  98.         SM_ERROR(TYPE_LOG, errno);
  99.     }
  100. #ifdef DEBUG
  101.     if(FastPathOnly) {
  102.         /*
  103.             no longer the case: see admin_ShutServer(),
  104.             comments about closing disks; where it sets
  105.             FastPathOnly.
  106.             SM_ASSERT(LEVEL_1, (volRec->diskrwPid == 0));
  107.             SM_ASSERT(LEVEL_1, (diskLink == NULL));
  108.         */
  109.     }
  110.     if(diskLink == NULL) {
  111.         SM_ASSERT(LEVEL_1, (FastPathOnly == TRUE));
  112.     }
  113.     if(volRec->diskrwPid == 0) {
  114.         SM_ASSERT(LEVEL_1, (FastPathOnly == TRUE));
  115.     }
  116. #endif DEBUG
  117.  
  118.     if (volRec->diskrwPid != 0) {
  119.         TRPRINT(TR_DISKRW|TR_DISK, TR_LEVEL_1,
  120.             ("Waiting on child %d for volume %s", 
  121.             volRec->diskrwPid, volRec->volNameRec->volName.name));
  122.  
  123.         /* 
  124.          * The volume has a disk process.  
  125.          * Wait for it to die. 
  126.          */
  127.  
  128.         if( waitpid(volRec->diskrwPid, 0, 0) < 0 ) {
  129.             TRPRINT(TR_DISKRW, TR_LEVEL_1, 
  130.                 ("Error %d waiting on child %d", errno, volRec->diskrwPid));
  131.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  132.         }
  133.  
  134.         TRPRINT(TR_DISKRW|TR_DISK, TR_LEVEL_1,
  135.             ("DISKRW %d for volume %s is gone.", 
  136.             volRec->diskrwPid, volRec->volNameRec->volName.name));
  137.         /* 
  138.          * disk process doesn't exist anymore
  139.          */
  140.         volRec->diskrwPid = 0;
  141.  
  142.         /*
  143.          *    free up all resources associated with the link
  144.          */
  145.         freeDiskLink(diskLink, esmFAILURE, esmDISKPROCDIED);
  146.     }
  147.  
  148.     /*
  149.      *    reply to the caller
  150.      */
  151.     return(esmNOERROR);
  152. }
  153.